<template>
  <div class="login">
    <h1>登录</h1>
    <el-form :model="managerInfo" label-width="100px">
      <el-form-item label="账号">
        <el-input v-model="managerInfo.accountManager"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="managerInfo.passwordManager"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button  type="primary" @click="submit">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
//组件暴露
import {sendRequest} from "@/util/request";

export default {
  name: "LoginInfo",
  data() {
    return {
      managerInfo: {
        accountManager: '',
        passwordManager: ''
      },
    }
  },
  methods:{
    submit(){
      sendRequest(
          "post",
          "manager/login",
          {accountManager:this.managerInfo.accountManager,passwordManager:this.managerInfo.passwordManager}
      ).then((res)=>{
        console.log(res)
        if(res.code==200){
          alert("登录成功啦!")
          //保存token到localStorage
          localStorage.setItem("token",res.token)
          //跳转到主页面
          this.$router.push("/mainInfo");
        }else {
          alert("登录失败")
        }
      })
    },

  }
}
</script>
<!-- scoped:样式只对当前的组件生效 -->
<style scoped>
.login{
  width: 350px;
  height: 300px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  border-radius: 5px;
  padding: 35px 35px 15px;
  border: 1px solid #ccc;
}
</style>
